package com.ruoyi.base;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ruoyi.config.GdApiConfig;
import com.ruoyi.enums.GDApiRequestUrlEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class HttpUtilService {

    @Autowired
    private GdApiConfig gdApiConfig;

    public JSONObject sendGetRequest(String code) {
        // 获取高德API的URL
        String url = GDApiRequestUrlEnum.WEATHER_FORECAST.getUrl();

        // 构建请求参数
        String params = "key=" + gdApiConfig.getKey() +code;

        // 发送GET请求
        String response = HttpUtil.get(url + "?" + params);

        // 解析响应JSON
        return JSONUtil.parseObj(response);
    }
}
